%计算节点矢量
classdef GetKnots
    properties
        data
        dataPara
        k
        ctrPnums
    end
    methods
        function obj = GetKnots(a)
            obj.data = a.data;%数据点 得到个数
            obj.dataPara = a.dataPara;%数据点参数
            obj.k = a.k;%次数
            obj.ctrPnums = a.ctrPnums;%控制点个数
        end
        function knots = AVG_KTP(obj)
            m = size(obj.data,1);
            n = obj.ctrPnums;
            u = obj.dataPara;
            knots = zeros(1,n+obj.k+1);
            knots(n+1: n+obj.k+1) = 1;
            if m == n
                for j = 1:(n-obj.k-1)  
                    knots(obj.k+j+1) = sum(u(j+1:j+obj.k)) / obj.k;
                end
            end
            if m>n
                c = m / (n - obj.k);
                for j = 1:n-obj.k-1
                    i = floor(j * c);
                    a = j*c - i;
                    knots(obj.k+j+1) = (1-a)* u(i) + a * u(i+1);
                end
            end
        end
        function knots = UAVG(obj)
            m = size(obj.data,1);
            n = obj.ctrPnums;
            u = obj.dataPara;
            knots = zeros(1,n+obj.k+1);
            knots(n+1: n+obj.k+1) = 1;
            for j = 1:(n-obj.k-1)
                knots(j+obj.k+1) = sum(u(j+1:j+obj.k+m-n))/(obj.k+m-n);
            end
        end
    end 
end